const Mock = require('mockjs')
const Random = Mock.Random
const category = [{
    value: 'zhinan',
    label: '指南',
    children: [{
        value: 'shejiyuanze',
        label: '设计原则',
        children: [{
            value: 'yizhi',
            label: '一致'
        }, {
            value: 'fankui',
            label: '反馈'
        }, {
            value: 'xiaolv',
            label: '效率'
        }, {
            value: 'kekong',
            label: '可控'
        }]
    }, {
        value: 'daohang',
        label: '导航',
        children: [{
            value: 'cexiangdaohang',
            label: '侧向导航'
        }, {
            value: 'dingbudaohang',
            label: '顶部导航'
        }]
    }]
}, {
    value: 'zujian',
    label: '组件',
    children: [{
        value: 'basic',
        label: 'Basic',
        children: [{
            value: 'layout',
            label: 'Layout 布局'
        }, {
            value: 'color',
            label: 'Color 色彩'
        }, {
            value: 'typography',
            label: 'Typography 字体'
        }, {
            value: 'icon',
            label: 'Icon 图标'
        }, {
            value: 'button',
            label: 'Button 按钮'
        }]
    }, {
        value: 'form',
        label: 'Form',
        children: [{
            value: 'radio',
            label: 'Radio 单选框'
        }, {
            value: 'checkbox',
            label: 'Checkbox 多选框'
        }, {
            value: 'input',
            label: 'Input 输入框'
        }, {
            value: 'input-number',
            label: 'InputNumber 计数器'
        }, {
            value: 'select',
            label: 'Select 选择器'
        }, {
            value: 'cascader',
            label: 'Cascader 级联选择器'
        }, {
            value: 'switch',
            label: 'Switch 开关'
        }, {
            value: 'slider',
            label: 'Slider 滑块'
        }, {
            value: 'time-picker',
            label: 'TimePicker 时间选择器'
        }, {
            value: 'date-picker',
            label: 'DatePicker 日期选择器'
        }, {
            value: 'datetime-picker',
            label: 'DateTimePicker 日期时间选择器'
        }, {
            value: 'upload',
            label: 'Upload 上传'
        }, {
            value: 'rate',
            label: 'Rate 评分'
        }, {
            value: 'form',
            label: 'Form 表单'
        }]
    }, {
        value: 'data',
        label: 'Data',
        children: [{
            value: 'table',
            label: 'Table 表格'
        }, {
            value: 'tag',
            label: 'Tag 标签'
        }, {
            value: 'progress',
            label: 'Progress 进度条'
        }, {
            value: 'tree',
            label: 'Tree 树形控件'
        }, {
            value: 'pagination',
            label: 'Pagination 分页'
        }, {
            value: 'badge',
            label: 'Badge 标记'
        }]
    }, {
        value: 'notice',
        label: 'Notice',
        children: [{
            value: 'alert',
            label: 'Alert 警告'
        }, {
            value: 'loading',
            label: 'Loading 加载'
        }, {
            value: 'message',
            label: 'Message 消息提示'
        }, {
            value: 'message-box',
            label: 'MessageBox 弹框'
        }, {
            value: 'notification',
            label: 'Notification 通知'
        }]
    }, {
        value: 'navigation',
        label: 'Navigation',
        children: [{
            value: 'menu',
            label: 'NavMenu 导航菜单'
        }, {
            value: 'tabs',
            label: 'Tabs 标签页'
        }, {
            value: 'breadcrumb',
            label: 'Breadcrumb 面包屑'
        }, {
            value: 'dropdown',
            label: 'Dropdown 下拉菜单'
        }, {
            value: 'steps',
            label: 'Steps 步骤条'
        }]
    }, {
        value: 'others',
        label: 'Others',
        children: [{
            value: 'dialog',
            label: 'Dialog 对话框'
        }, {
            value: 'tooltip',
            label: 'Tooltip 文字提示'
        }, {
            value: 'popover',
            label: 'Popover 弹出框'
        }, {
            value: 'card',
            label: 'Card 卡片'
        }, {
            value: 'carousel',
            label: 'Carousel 走马灯'
        }, {
            value: 'collapse',
            label: 'Collapse 折叠面板'
        }]
    }]
}, {
    value: 'ziyuan',
    label: '资源',
    children: [{
        value: 'axure',
        label: 'Axure Components'
    }, {
        value: 'sketch',
        label: 'Sketch Templates'
    }, {
        value: 'jiaohu',
        label: '组件交互文档'
    }]
}]
const tableList = Mock.mock({
    'data|56': [{
        'id|+1': 10001,
        'SPU|+1': 20190102,
        type: 'own',
        model: '10000SN9',
        imgUrl: Random.dataImage('160x160', '产品图片'),
        'code|+1': 1000101,
        goodsName: '优唯斯（UVEX）ultravision系列9301603安全眼罩气密性镜框内防雾外防刮 红色（1副）',
        supplierName: '云中鹤科技股份有限公司',
        resource: '自有',
        category: [{
            'id|+1': 1001,
            name: '工业品'
        },
        {
            'id|+1': 1001001,
            parent_id: 1001,
            name: '个人防护'
        },
        {
            'id|+1': 1001300,
            parent_id: 1001,
            name: '眼脸部防护'
        }],
        brand: '优唯斯',
        'market_price|+1': 85.12,
        'cost_price|+1': 80,
        'standard_price|+1': 84,
        updateTime: '2018-04-02 10:25',
        updateWay: '自动',
        erp_code: 2000100,
        sku_id: 89001,
        status: '上架',
        barcode: 20190403,
        label: ['优选', '热销'],
        profit: 0.32,
        tax_rate: 0.13,
        'site_num|+1': 2,
        sku: {
            model: 'SYS10010',
            color: '白色',
            size: '1.8 * 1.6'
        }
    },
    {
        'id|+1': 100020,
        'SPU|+1': 20190202,
        type: 'supplier',
        model: '10000SN9',
        imgUrl: Random.dataImage('160x160', '产品图片'),
        'code|+1': 1000101,
        goodsName: '水星家纺 大提花四件套 英伦轻奢床单被罩被套床上用品套件 爱伦思特(玉色)加大双人1.8米床',
        supplierName: '云中鹤科技股份有限公司',
        resource: '供应商',
        category: [{
            'id|+1': 1300,
            name: '家纺'
        },
        {
            'id|+1': 1300001,
            parent_id: 1300,
            name: '床上用品'
        },
        {
            'id|+1': 1300101,
            parent_id: 1300,
            name: '四件套'
        }],
        brand: '水星',
        'market_price|+1': 86.12,
        'cost_price|+1': 83,
        'standard_price|+1': 150,
        updateTime: '2018-04-01 10:25',
        updateWay: '自动',
        erp_code: 2000150,
        sku_id: 89002,
        status: '停售',
        barcode: 20190403,
        label: ['优选', '热销'],
        profit: 0.12,
        tax_rate: 0.13,
        'site_num|+1': 34,
        sku: {
            model: 'SYS10010',
            color: '黑色',
            size: '1.8 * 1.6'
        }
    },
    {
        'id|+1': 100120,
        'SPU|+1': 20190302,
        type: 'jd',
        model: '10100SN9',
        imgUrl: Random.dataImage('160x160', '产品图片'),
        'code|+1': 1000101,
        goodsName: 'THERMOS膳魔师保温杯500ml高真空不锈钢超轻系列JNL-501 CBK',
        supplierName: '云中鹤科技股份有限公司',
        resource: '京东',
        category: [{
            'id|+1': 1500,
            name: '厨具'
        },
        {
            'id|+1': 1500001,
            parent_id: 1500,
            name: '水具酒具'
        },
        {
            'id|+1': 1500201,
            parent_id: 1500,
            name: '保温杯'
        }],
        brand: '膳魔师',
        'onlinePrice|+1': 85,
        'agreementPrice|+1': 80,
        'packagePrice|+1': 84,
        updateTime: '2018-04-06 10:25',
        updateWay: '自动',
        erp_code: 2001480,
        sku_id: 89003,
        status: '待审核',
        postage: 20,
        'site_num|+1': 34,
        sku: {
            model: 'SYS10010',
            color: '红色',
            size: '1.8 * 1.6'
        }
    },
    {
        'id|+1': 102340,
        'SPU|+1': 20190402,
        type: 'yanxuan',
        model: '10300SN9',
        imgUrl: Random.dataImage('160x160', '产品图片'),
        'code|+1': 1000101,
        goodsName: '广誉远 龟龄集酒整箱 250ml盒*12',
        supplierName: '云中鹤科技股份有限公司',
        resource: '严选',
        category: [{
            'id|+1': 1700,
            name: '厨具'
        },
        {
            'id|+1': 1700001,
            parent_id: 1700,
            name: '水具酒具'
        },
        {
            'id|+1': 1700301,
            parent_id: 1700,
            name: '保温杯医药保健'
        },
        {
            'id|+1': 1700501,
            parent_id: 1700,
            name: '营养成分'
        }],
        brand: '广誉远',
        'onlinePrice|+1': 85,
        'agreementPrice|+1': 80,
        'packagePrice|+1': 84,
        updateTime: '2018-04-08 10:25',
        updateWay: '手动',
        erp_code: 2000260,
        sku_id: 89004,
        status: '审核通过',
        postage: 20,
        'site_num|+1': 122,
        sku: {
            model: 'SYS10010',
            color: '蓝色',
            size: '1.8 * 1.6'
        }
    }]
})

const brand = [
    {
        id: 1,
        name: '维仕蓝',
        cname: 'weslate'
    },
    {
        id: 2,
        name: '斯顿',
        cname: 'stone'
    },
    {
        id: 3,
        name: '攀能',
        cname: 'panneng'
    }
]
const goodsLabel = [
    {
        id: 1,
        name: '全部',
        cname: 'all'
    },
    {
        id: 2,
        name: '热销',
        cname: 'hot'
    },
    {
        id: 3,
        name: '精选',
        cname: 'jingxuan'
    }
]
const supplier = [
    {
        id: 1,
        name: '全部',
        cname: 'all'
    },
    {
        id: 2,
        name: '中国移动',
        cname: 'cmcc'
    },
    {
        id: 3,
        name: '中国联通',
        cname: 'chinaUniom'
    },
    {
        id: 4,
        name: '中国电信',
        cname: 'chinaNet'
    }
]
const tableData = function (req) {
    const body = JSON.parse(req.body)
    const tableData = Object.assign([], tableList.data)
    let { id, type, currentPage = 1, pageSize = 10 } = body.data
    let currData = []
    let totalData = []
    let detailData = {}
    if (type) {
        tableData.forEach(el => {
            if (type === el.type) {
                totalData.push(el)
                if (id && id === el.id) {
                    detailData = el
                }
            }
        })
    } else {
        tableData.forEach(el => {
            if (el.type === 'own') {
                totalData.push(el)
            }
        })
    }
    if (id) {
        return { data: detailData, code: '200' }
    }
    currData = Object.assign([], totalData)
    let pageIndex = (currentPage && pageSize && (currentPage - 1) * pageSize) || 0
    let data = (pageSize && currData.splice(pageIndex, pageSize)) || currData
    return {
        data: data,
        totalCount: totalData.length,
        totalPage: Math.ceil(totalData.length / pageSize)
    }
}
const submitData = function (req) {
    // const body = JSON.parse(req.body)
    return {
        data: {
            code: '200',
            message: '操作成功'
        }
    }
}
export default {
    category,
    tableData,
    brand,
    goodsLabel,
    supplier,
    submitData
}
